//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.zy.gpdemo.print;

import com.runqian.report4.view.applet.AReport;
import java.awt.print.PageFormat;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.util.StringTokenizer;
import javax.print.PrintService;

public class QuieeDirectPrintJobJava {
    private String appRoot;
    private String dataServlet;
    private String reportName;
    private String type;
    private String reportParams;
    private String cacheId;
    private String needSetPageSize;
    private String paramCharset;
    private String savePrintSetup;
    private String printServiceName;

    public QuieeDirectPrintJobJava(String appRoot, String reportName, String reportParams, String printServiceName) {
        this.init(appRoot, reportName, reportParams, printServiceName);
    }

    public void init(String appRoot, String reportName, String reportParams, String printServiceName) {
        this.appRoot = appRoot;
        this.reportName = reportName;
        this.reportParams = reportParams;
        this.printServiceName = printServiceName;
        this.dataServlet = "/reportServlet?action=1";
        this.type = "file";
        this.cacheId = null;
        String needPrintPrompt = "no";
        String needSelectPrinter = "no";
        this.savePrintSetup = "no";
        this.needSetPageSize = "no";
        this.paramCharset = "GBK";
    }

    public void print() {
        String s = null;
        this.reportName = this.reportName.trim();
        PrinterJob job = PrinterJob.getPrinterJob();
        PrintService[] pss = PrinterJob.lookupPrintServices();
        Boolean isMatchprintService = false;
        int count;
        if (this.printServiceName != null && !"".equals(this.printServiceName)) {
            PrintService[] var8 = pss;
            count = pss.length;

            for(int var6 = 0; var6 < count; ++var6) {
                PrintService ps = var8[var6];
                if (ps.getName().equals(this.printServiceName) || ps.getName().contains(this.printServiceName)) {
                    try {
                        job.setPrintService(ps);
                        isMatchprintService = true;
                        break;
                    } catch (PrinterException var15) {
                    }
                }
            }
        }

        if (!isMatchprintService) {
            this.printServiceName = null;
        }

        boolean bsavePrintSetup = "yes".equalsIgnoreCase(this.savePrintSetup);
        PageFormat outerPf = null;
        count = 1;
        if (this.reportName.startsWith("{")) {
            int index = 0;

            for(int len = this.reportName.length(); index < len; ++count) {
                index = this.reportName.indexOf("{", index);
                if (index < 0) {
                    break;
                }

                int end = this.reportName.indexOf("}", index);
                s = this.reportName.substring(index + 1, end).trim();
                index = end + 1;
                String name = s;
                String paramString = null;
                int pos = s.indexOf("(");
                if (pos > 0) {
                    paramString = s.substring(pos + 1, s.length() - 1).trim();
                    name = s.substring(0, pos).trim();
                }

                if (!name.toLowerCase().endsWith(".raq") && !name.toLowerCase().endsWith(".rat")) {
                    name = name + ".raq";
                }

                AReport report = new AReport();
                report.appRoot = this.appRoot;
                report.cachedId = this.cacheId;
                report.dataServlet = this.dataServlet;
                report.fileName = name;
                if (paramString != null) {
                    report.paramString = paramString;
                    report.paramEncode = this.paramCharset;
                }

                report.srcType = this.type;
                report.job = job;
                report.savePrintSetup = bsavePrintSetup;
                report.outerPf = outerPf;
                if (count == 1 && this.needSetPageSize.equalsIgnoreCase("yes")) {
                    report.bSetPageSize = true;
                    outerPf = report.print();
                } else {
                    report.print();
                }
            }
        } else {
            for(StringTokenizer st = new StringTokenizer(this.reportName, ","); st.hasMoreTokens(); ++count) {
                String name = st.nextToken().trim();
                if (!name.toLowerCase().endsWith(".raq") && !name.toLowerCase().endsWith(".rat")) {
                    name = name + ".raq";
                }

                AReport report = new AReport();
                report.appRoot = this.appRoot;
                report.cachedId = this.cacheId;
                report.dataServlet = this.dataServlet;
                report.fileName = name;
                report.paramString = this.reportParams;
                report.paramEncode = this.paramCharset;
                report.srcType = this.type;
                report.job = job;
                report.savePrintSetup = bsavePrintSetup;
                report.outerPf = outerPf;
                if (count == 1 && this.needSetPageSize.equalsIgnoreCase("yes")) {
                    report.bSetPageSize = true;
                    outerPf = report.print();
                } else {
                    report.print();
                }
            }
        }

    }
}